import sys
import os
sys.path.append(os.getcwd()) # 将当前目录加入sys.path

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import QObject

#from ui.Ui_MainWindow import Ui_MainWindow as mainWindow
#from ui.Ui_ArimaWindow import Ui_MainWindow as arimaWindow
from dialog.main import mainWindow
from dialog.arima import arimaWindow
from dialog.calculate import calculateWindow

'''
控制各个页面展示的类
'''
class Controller:
    def __init__(self):
        self.main = mainWindow()
        self.arima = arimaWindow()
        self.calculate = calculateWindow()
    
    def show_main(self):
        # 创建 main 窗口对象并显示
        # 关闭其余窗口对象
        self.main.main2arima.connect(self.show_arima)
        self.main.openCalculate.connect(self.show_calculate)
        self.main.show()
        self.arima.close()
    
    def show_arima(self):
        # 创建 arima 窗口对象并显示
        # 关闭其余窗口对象
        self.arima.arima2main.connect(self.show_main)
        self.arima.openCalculate.connect(self.show_calculate)
        # 给arima页面传文件
        self.arima.file = self.main.file
        self.arima.Primarykey = self.main.Primarykey
        self.arima.key1 = self.main.key1
        self.arima.key2 = self.main.key2
        self.arima.show()
        self.main.close()

    def show_calculate(self):
        # 创建 calculate 窗口对象并展示

        # 给calculate页面传数据
        self.calculate.test_data = self.arima.y1
        self.calculate.forecast_data = self.arima.y2

        if self.main.arimaisTrained:
            self.calculate.arimaisTrained = True
        if self.main.lssvmisTrained:
            self.calculate.lssvmisTrained = True
        if self.main.rnnisTrained:
            self.calculate.rnnisTrained = True
        if self.main.lstmisTrained:
            self.calculate.lstmisTrained = True
        if self.main.informerisTrained:
            self.calculate.informerisTrained = True

        if self.arima.mfeCheck.isChecked():
            self.calculate.mfeisChecked = True
        if self.arima.maeCheck.isChecked():
            self.calculate.maeisChecked = True
        if self.arima.mapeCheck.isChecked():
            self.calculate.mapeisChecked = True
        if self.arima.mpeCheck.isChecked():
            self.calculate.mpeisChecked = True
        if self.arima.mseCheck.isChecked():
            self.calculate.mseisChecked = True
        if self.arima.sseCheck.isChecked():
            self.calculate.sseisChecked = True
        if self.arima.smseCheck.isChecked():
            self.calculate.smseisChecked = True
        if self.arima.rmseCheck.isChecked():
            self.calculate.rmseisChecked = True
        if self.arima.nmseCheck.isChecked():
            self.calculate.nmseisChecked = True

        self.calculate.show_cal()
        self.calculate.show()